<html>
<head>
    <title>第一个本地页面</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="./style.css" />
</head>

<body>
    这是第一个本地页面<br />
    它的地址是：
    <script src="./a.js"></script>
    <a href="index.html" target="_blank">打开一个新窗口</a>
    <br />
    <div id="test"></div>
    <img src="../img/web.png"/>
    <button onclick="ipc_send()">IPC string 测试</button>
    <button onclick="ipc_send2()">IPC string 有返回，无参数，测试</button>
    <button onclick="ipc_send_no_back()">IPC string 无返回，无参数，测试</button>
    <button onclick="ipc_send_no_back1()">IPC string 无返回，有参数，测试</button>
    <button onclick="ipc_send_int_no_back()">IPC int 无返回测试</button>
    <button onclick="ipc_send_int()">IPC int 测试</button>
    <button onclick="ipc_send_list()">IPC list 测试</button>
    <button onclick="ipc_send_list1()">IPC list 无返回测试</button>
    <button onclick="ipc_send_list2()">IPC list 返回多参数测试</button>

    <button onclick="js_on1()">js_on 单参数</button>
    <button onclick="js_on2()">js_on 多参数</button>
    <button onclick="js_on3()">js_on 无参返回单参数</button>
    <button onclick="js_on4()">js_on 多参数返回多参数</button>
    <button onclick="js_on5()">js_on 无参无返回</button>

    <script>
        // 单参数
        function ipc_send() {
            ipcRenderer.send('example_event', "test", (response) => {
                console.log("rsponse string: ")
                console.log(response);
            });
        }
        function ipc_send_no_back() {
            ipcRenderer.send('example_event_no');
        }
        function ipc_send_no_back1() {
            ipcRenderer.send('example_event_no1', 'test111');
        }

        function ipc_send2() {
            ipcRenderer.send('example_event2', (response) => {
                console.log("rsponse: ")
                console.log(response);
            });
        }

        function ipc_send_int() {
            ipcRenderer.send('example_event_int', 999, (response) => {
                console.log("rsponse int: ")
                console.log(response);
            });
        }

        // 多参数
        function ipc_send_list() {
            ipcRenderer.send('send_test_list', [true, 100, 99.99, 'tests'], (response) => {
                console.log("rsponse: ")
                console.log(response);
            });
        }

        function ipc_send_list1() {
            ipcRenderer.send('send_test_list1', [true, 100, 99.99, 'tests']);
        }

        function ipc_send_list2() {
            ipcRenderer.send('send_test_list2', [true, 100, 99.99, 'tests'], (param1, param2) => {
                console.log("param1: ", param1)
                console.log("param2: ", param2)
            });
        }

        // js_on
        function js_on1() {
            ipcRenderer.send("js_on1")
        }
        function js_on2() {
            ipcRenderer.send("js_on2")
        }
        function js_on3() {
            ipcRenderer.send("js_on3")
        }
        function js_on4() {
            ipcRenderer.send("js_on4")
        }
        function js_on5() {
            ipcRenderer.send("js_on5")
        }
       
        function ipc_call_js() {
            ipcRenderer.on('call_js1', (arg) => {
                console.log("cangjie call ......param:", arg)
                document.getElementById("test").innerHTML = "<p>仓颉调用js</p>"
                return 78881
            })
            ipcRenderer.on('call_js2', (arg1, arg2) => {
                console.log("cangjie call ......param:")
                console.log("arg1:", arg1)
                console.log("arg2:", arg2)
                return 78882
            })
            ipcRenderer.on('call_js3', () => {
                console.log("cangjie call ......param:")
                return 78883
            })
            ipcRenderer.on('call_js4', (arg1, arg2) => {
                console.log("cangjie call ......param:")
                console.log("arg1:", arg1)
                console.log("arg2:", arg2)
                return [100, 'test_list']
            })
            ipcRenderer.on('call_js5', () => {
                console.log("cangjie call ......no param no return:")
            })

        }
        ipc_call_js()

    </script>
    </script>

</body>

</html>